<template>
	<view v-if="is_init">
		<uni-popup-input @close="on_close">

			<view class="banmi_flex" style="">
				<view class="  p20" style="width: 100%;padding-right: 60px;padding-left: 20px;">

					<view class="banmi_flex a-c  p-b-20" style="width: 600px;">
						<view class="f-14 c-7" style="width: 110px;">
							导航名称
						</view>
						<uni-easyinput v-model="find.name" placeholder="导航名称">
						</uni-easyinput>
					</view>



					<view class=" banmi_flex a-c   p-b-20" style="width: 600px;">
						<view class="f-14 c-7" style="width: 110px;">
							排序值越小排序越高
						</view>

						<uni-easyinput v-model="find.sort" type="number" placeholder="数字,如0">
						</uni-easyinput>
					</view>

					<view class="banmi_flex  p-b-20">

						<view class="banmi_input_edit a-c">
							<view class="banmi_input_edit_name">
								图标
							</view>
							<view class="banmi_input_val">
								<upImg ref="upimg" :val='1' name="图片" :count="1" :list="find.img" t_type="images"
									@confirm="confirm_img">
								</upImg>
							</view>
						</view>


					</view>

					<view v-if="find.type==1" class="banmi_flex a-c  p-b-20" style="width: 600px;">
						<view class="f-14 c-7" style="width: 110px;">
							小程序APPid
						</view>
						<uni-easyinput v-model="find.appId" placeholder="其他小程序appId">
						</uni-easyinput>
					</view>
					<view v-if="find.type==1" class="banmi_flex a-c  p-b-20" style="width: 600px;">
						<view class="f-14 c-7" style="width: 110px;">
							小程序路径
						</view>
						<uni-easyinput v-model="find.path" placeholder="其他小程序path路径">
						</uni-easyinput>
					</view>

				</view>

			</view>

			<view class="  p20" style="margin-left: 445px;">
				<button class=" " @click="on_users_cx()" type="primary" style="width: 200px;" size="mini">保存</button>
			</view>

		</uni-popup-input>
	</view>
</template>

<script>
	export default {
		components: {

		},
		props: {
			id: {
				type: Number,
				default: 0

			},
		},
		data() {
			return {
				find: {
					name: '',
					sort: 0,
					img: '',
					appId: '123',
					path: '456',
					type: 0,
				},
				isShow: false,
				list: [],
				total: 0,
				page: 1,

				is_top_height: false,
				is_init: false,
				lbs_sing: '',
				shop_search_placeholder: '',
				shop_name: '',

				url: '',
				type_name: '请选择类型'
			}
		},
		mounted() {
			this.init();
		},
		methods: {
			confirm_img(vals) {
				if (vals.length == 0) {
					this.find.img = ''
					return
				}
				this.find.img = vals[0]['attachment']
			},

			init() {
				var that = this;
				var id = that.id;
				if (id == 0) {
					this.is_init = true;
					return
				}
				let requestParams = {
					id: id,
				};
				this.Http.post('banmitongcheng/admin/Shopnav/finds_dhxqbj',requestParams).then(ret => {
					var ret = ret;
					this.find = ret.data.find;
			 
					this.is_init = true;

				})






			},
			on_tab(index) {
				this.tabindex = index;
			},


			on_users_cx() {

				var that = this;
				var name = that.find['name'];
				var img = that.find['img'];
				var sort = that.find['sort'];
				var appId = that.find['appId'];
				var path = that.find['path'];
				var type = that.find['type'];

				if (!name) {
					uni.showToast({
						title: '请输入导航名称',
						icon: 'none'
					})
					return
				}

 
				if (!img) {
					uni.showToast({
						title: '请上传图片',
						icon: 'none'
					})
					return
				}
				if (type == 1) {
					if (!path) {
						uni.showToast({
							title: '请输入小程序路径',
							icon: 'none'
						})
						return
					}
					if (!appId) {
						uni.showToast({
							title: '请输入小程序appId',
							icon: 'none'
						})
						return
					}

				}



				if (that.id > 0) {
					var id = that.id; 
					let requestParams = {
						name: name,
						img: img,
						sort: sort,
						id: id,
						appId: appId,
						path: path,
						type: type
					};
					this.Http.post('banmitongcheng/admin/Shopnav/updates_bjdhxx', requestParams).then(ret => {
					
						uni.showToast({
							title: ret.msg,
							icon: 'none'
						})
						if (ret.status == 200) {
							this.is_init = false;
							this.$emit("confirm");

						}

					})


					return
				}
				if (name == undefined) {
					name = '';
				}
				if (sort == undefined) {
					sort = '';
				}
				if (img == undefined) {
					img = '';
				}


				let requestParams = {
					name: name,
					img: img,
					appId: appId,
					sort: sort,
					path: path,
					type: type
				};

				this.Http.post('banmitongcheng/admin/Shopnav/adds_zjdh',requestParams).then(ret => {
				
					uni.showToast({
						title: ret.msg,
						icon: 'none'
					})
					if (ret.status == 200) {
						this.is_init = false;
						this.$emit("confirm");

					}
				})

			},
			on_close() {
				this.is_init = false;
				this.$emit("close");
			},


		}
	}
</script>

<style>
	button::after {
		border: none;
	}

	.top_head {
		background-color: #F8F8F8;
		width: 100%;
		top: 0;
		left: 0;
		z-index: 999;
		position: sticky
	}

	.but {
		width: 120rpx;
		height: 100rpx;
		padding: 0;
		border: 0;
		background-color: transparent;
		outline: none;
	}
</style>